home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 2 / Mac Magazin and MacEasy Magazine CD - Issue 02.iso / Sharewarebibliothek / Applikationen / Alpha.5.81 folder / Tcl / UserCode / editLastFile.tcl < prev    next >
Text File  |  1994-03-08  |  2KB  |  97 lines

  1. # FILE: editLastFile.tcl
  2. #
  3. # LAST UPDATE: 01/08/93 5:53:54 AM
  4. #
  5. # This file contains the following TCL procedure(s):
  6. #
  7. #     closeHook -- renames original and adds support functionality
  8. #     editLastFile -- allows editing previous file closed (bound CMD-SHIFT-W)
  9. #    editRecentFile -- allows a list pick of recent files
  10.  
  11. # COPYRIGHT:
  12. #
  13. #    Copyright © 1992,1993 by David C. Black All rights reserved.
  14. #    Portions copyright © 1990, 1991, 1992 Pete Keleher. All Rights Reserved.
  15. #
  16. #    Redistribution and use in source and binary forms are permitted
  17. #    provided that the above copyright notice and this paragraph are
  18. #    duplicated in all such forms and that any documentation,
  19. #    advertising materials, and other materials related to such
  20. #    distribution and use acknowledge that the software was developed
  21. #    by David C. Black in conjunction with Pete Keleher.
  22. #
  23. #    THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
  24. #    IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  25. #    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  26. #
  27. ################################################################################
  28.  
  29. # AUTHOR
  30. #
  31. #    David C. Black
  32. #    Internet: black@mpd.tandem.com (preferred)
  33. #    GEnie:    D.C.Black
  34. #    USnail:   6217 John Chisum Lane, Austin, TX 78749
  35. #
  36. ################################################################################
  37.  
  38. proc editLastFile {} {
  39.     global lastStack
  40.     set i [llength $lastStack]
  41.     if {!$i} {
  42.         beep
  43.         message "Nothing to open"
  44.         return
  45.     }
  46.     set lastFile [lindex $lastStack [incr i -1]]
  47.     set lastStack [lrange $lastStack 0 [incr i -1]]
  48.     if {[file readable $lastFile]} {
  49.         edit $lastFile
  50.     } else {
  51.         beep
  52.         alertnote "Missing $lastFile"
  53.     }
  54. }
  55. #endproc editLastFile
  56.  
  57. proc editRecentFile {} {
  58.     global lastStack
  59.     if {![llength $lastStack]} {
  60.         beep
  61.         alertnote "Nothing to open"
  62.         return
  63.     }
  64.     set lastFile [listpick [lsort $lastStack]]
  65.     if {[string length $lastFile]} {
  66.         set i [lsearch $lastStack $lastFile]
  67.         set lastStack [lreplace $lastStack $i $i]
  68.         if {[file readable $lastFile]} {
  69.             edit $lastFile
  70.         } else {
  71.             beep
  72.             alertnote "Missing $lastFile"
  73.         }
  74.     }
  75. }
  76. #endproc editRecentFile
  77.  
  78. if {[info procs original-closeHook] != "original-closeHook"} {
  79.  
  80.     rename closeHook original-closeHook
  81.  
  82. set lastStack {}
  83. proc closeHook {name} {
  84.     set result [eval original-closeHook {$name}]
  85.     global lastStack
  86.     lappend lastStack $name
  87.     return $result
  88. }
  89. #endproc closeHook
  90.  
  91. addMenuItem fileUtils editRecentFile…
  92. bind 'w' <cs> editLastFile
  93.  
  94. }
  95. #endif
  96.  
  97.